package code.example.base.util.concurrent.threadstate;

import code.example.tool.LogFactory;
import code.example.tool.SleepUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 *  join 线程 状态是 Waiting
 */
@RunWith(JUnit4.class)
public class JoinTest {
    public Thread startOneThread(final Thread mainThread){
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                SleepUtils.sleepSecond(5);
                Thread.State state =  mainThread.getState();
                LogFactory.getLog().info("main thead state:"+state);
            }
        },"RunningThread");
        t.start();
        return t;
    }

    @Test
    public void JoinOneThead(){
        Thread t = startOneThread(Thread.currentThread());
        try {
            LogFactory.getLog().info("main thread start join:");
            t.join();
            LogFactory.getLog().info("main thread  join finish!");
        }catch (Exception e){
            LogFactory.getLog().error(e);
        }
    }
}
